//
//  YYScanCell.m
//  Project
//
//  Created by Yown on 2024/1/25.
//

#import "YYScanCell.h"

#import <BIToolModule/BIProjectDefine.h>

#import <BIProjectModule/BIAppDefine.h>
#import <BIToolModule/UIView+Custom.h>

#import <SDWebImage/SDWebImage.h>

@interface YYScanCell ()

@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *deviceImageView;
@property (weak, nonatomic) IBOutlet UILabel *deviceLabel;
@property (weak, nonatomic) IBOutlet UILabel *deviceUUIDLabel;
@property (weak, nonatomic) IBOutlet UIButton *connectButton;

@end

@implementation YYScanCell

#pragma mark - Overrid Method

+ (CGFloat)cellHeight {
    return 80;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor clearColor];
    
    self.bgView.backgroundColor = [UIColor loadColorFromString:@"#FFFFFF"];
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 12;
    
    self.deviceImageView.layer.masksToBounds = YES;
    self.deviceImageView.layer.cornerRadius = 28;
    self.deviceImageView.contentMode = UIViewContentModeScaleToFill;
    
    self.deviceLabel.textColor = [UIColor loadColorFromString:@"#333333"];
    self.deviceLabel.font = BIFont(16);
    
    self.deviceUUIDLabel.textColor = [UIColor loadColorFromString:@"#BDBDBD"];
    self.deviceUUIDLabel.font = BIFont(12);
    
    self.connectButton.layer.masksToBounds = YES;
    self.connectButton.layer.cornerRadius = 15;
    self.connectButton.titleLabel.font = BIFont(14);
    [self.connectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.connectButton setTitle:BILocalizedString(@"scan_connect") forState:UIControlStateNormal];
    self.connectButton.backgroundColor = [UIColor loadColorFromString:@"#4CB49E"];
}

- (void)reloadDeivceName:(NSString *)name image:(NSString *)image uuid:(NSString *)uuid {
    self.deviceLabel.text = name;
    [self.deviceImageView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"scan_device_placeholder"]];
    self.deviceUUIDLabel.text = uuid;
}

- (void)reloadDeivceName:(NSString *)name image:(NSString *)image uuid:(NSString *)uuid buttonText:(NSString *)buttonText {
    self.deviceLabel.text = name;
    [self.deviceImageView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"scan_device_placeholder"]];
    self.deviceUUIDLabel.text = uuid;
    if (buttonText.length > 0) {
        [self.connectButton setTitle:BILocalizedString(buttonText) forState:UIControlStateNormal];
        self.connectButton.hidden = NO;
    } else {
        self.connectButton.hidden = YES;
    }
}

#pragma mark - Action

- (IBAction)clickConnectButton:(id)sender {
    BISafeBlock(self.connectBlock);
}


@end
